<template>
	<view id="page">
		<nav-bar :navH="navH" :isTabar="false" :isHome="false" :pageName="title"></nav-bar>
		<view class="banner">
			<image src="../../static/30.jpg" mode="widthFix" lazy-load="true"></image>
			<view class="panel">
				<view class="logo">
					<image :src="detail.logo" mode="widthFix" lazy-load="true" class="logo" @error="imgError" v-if="detail.logo"></image>
					<image src="../../static/avatars_default.png" mode="widthFix" lazy-load="true" v-else></image>
					<image src='../../static/51.png' mode="widthFix" lazy-load="true" class="vip"></image>
				</view>
				<text class="name">{{detail.store_name}}</text>
				<view class="fans">
					<text style="display: inline-block; padding-right: 10upx; color: #666;">粉丝</text><text>{{detail.fans}}</text>
				</view>
				<text class="btn p" @click="cancelFllow(detail.doctor_id)" v-if="detail.is_attention === 1">已关注</text><text class="btn" @click="setFllow(detail.doctor_id)" v-else>关注</text><image src="../../static/28.png" mode="widthFix" lazy-load="true" class="link" v-show="detail.is_attention === 1"></image>
			</view>
		</view>
		<view class="summary">
			<text>{{detail.summary}}</text>
			<view class="btn" @click="goCase(detail.doctor_id)">查看我的案例</view>
		</view>
		<view class="aptitude">
			<text>资质</text>
			<view class="pic">
				<block v-for="(it, k1) in detail.qualification" :key="k1">
					<image :src="it" mode="widthFix" lazy-load="true" @click="previewImage(it)"></image>
				</block>
			</view>
		</view>
		<!-- 图文列表 -->
	    <view class="classify clearfloat">
			<view :class="['class-i', isOn === 0 ? 'on' : '']" @click='switchMenu(0)'>全部</view>
			<view :class="['class-i', isOn === 1 ? 'on' : '']" @click='switchMenu(1)'>视频({{spnum}})</view>
			<view :class="['class-i', isOn === 2 ? 'on' : '']" @click='switchMenu(2)'>图文({{zxnum}})</view>
	    </view>
		<!-- 图文列表 -->
		<!-- <pic-txt :lists="lists" v-if="hasRes"></pic-txt>
		<view class="nocont" v-else>暂无内容</view> -->
		<view class="nomore" v-if="isLoad"><image src='../../static/nomore_img.png' mode="widthFix"></image><text>没有更多了~</text></view>
		<scope-box :isLogin="isLogin" @isShow="isShow"></scope-box>
	</view>
</template>

<script>
	// import PicTxt from '../../components/pictxt/index.vue'
	import app from '../../common/index.js'
	export default {
		data() {
			return {
				title: '名医',
				navH: null,
				userInfo: {},
				isLogin: false,
				doctId: '',  // 医生ID
				detail: {},
				isOn: 0,
				hasRes: true,
				isLoad: false,
				page: 1,
				size: 10,
				handedData: [[],[],[]],  // 分类过的数据
				lists: [],
				spnum: '',
				zxnum: '',
			}
		},
		onLoad(options) {
			this.navH = this.$store.state.navHeight;
			this.doctId = options.id;
			// 获取本地用户信息
			this.userInfo = uni.getStorageSync('uinfo');
			if(!this.userInfo.id) {
				this.isLogin = true;
			}
			this.getHome();
			this.getPicTxt();
		},
		// 下拉刷新
		onPullDownRefresh() {
			this.page = 1;
			this.lists = [];
			this.handedData = [[],[],[]];
			// 获取本地用户信息
			this.userInfo = uni.getStorageSync('uinfo');
			this.getHome();
			this.getPicTxt()
			uni.stopPullDownRefresh();
		},
		// 上划加载
		onReachBottom() {
			if(!this.isLoad) {
				this.page = this.page+1;
				this.getPicTxt();
			}
		},
		// 分享转发
		onShareAppMessage() {
			return {
				title: '爱美指南针-名医',
				path: 'pages/hospitalhome/index?id='+ this.doctId,
			}
		},
		components: {
			// PicTxt,
		},
		methods: {
			/**
			 * @des 登录提示框
			 */
			isShow() {
				this.isLogin = false;
			},
			/**
			 * @des 获取主页内容
			 */
			getHome() {
				app.request({
					url: 'entry/wxapp/FamousDoctorDetail',
					data: {
						id: this.doctId,
						user_id: this.userInfo.id,
					}
				}, (ret) => {
					let d = ret.data;
					d["isFllow"] = 0;   // 临时预置参数
					this.detail = d;
				})
			},
			/**
			 * @des 关注
			 */
			setFllow(id) {
				app.request({
					url: 'entry/wxapp/Attention',
					data: {
						guan_user: this.userInfo.id,
						bguan_user: id,
					}
				}, (ret) => {
					console.log(ret);
					this.detail["is_attention"] = 1;
				})
			},
			/**
			 * @des 取消关注
			 */
			cancelFllow(id) {
				app.request({
					url: 'entry/wxapp/CancelAttention',
					data: {
						guan_user: this.userInfo.id,
						bguan_user: id,
					}
				}, (ret) => {
					console.log(ret);
					this.detail["is_attention"] = 0;
				})
			},
			/**
			 * @des 获取资讯列表
			 */
			getPicTxt() {
				app.request({
					url: 'entry/wxapp/FamousDoctorList',
					data: {
						doctor_id: this.doctId,
						user_id: this.userInfo.id,
					}
				}, (ret) => {
					console.log(ret);
					let d = ret.data, totalArr = this.handedData, len = d.data.length;
					this.zxnum = d.zx_num; this.spnum = d.video_num;
					if (d.total > 0) {
						this.hasRes = true;
						this.isLoad = len < this.size ? true : false;
						d.data.forEach((item, index) => {  // 此处做数据分类处理
							totalArr[0].push(item);
							if(item.is_video === '1') {
								totalArr[1].push(item);
							}else if(item.is_video === '0') {
								totalArr[2].push(item);
							}
						})
						this.handedData = totalArr;
						this.switchMenu(this.isOn);
					} else {
						this.hasRes = false;
					}
				})
			},
			/**
			 * @des 打开我的案例
			 */
			goCase(id) {
				uni.navigateTo({
					url: '../case/index?id='+ id,
				});
			},
			/**
			 * @des 预览图片
			 */
			previewImage(curImg) {
				console.log(this.detail.qualification)
				uni.previewImage({
					urls: this.detail.qualification,
					current: curImg,
				})
			},
			/**
			 * @des 切换菜单
			 */
			switchMenu(i) {
				this.isOn = i;
				this.lists = this.handedData[i];
			}
		}
	}
</script>

<style>
	.flex {margin: 20upx 0;}
	.flex .flex-i {width: 33.3%; padding: 0 10upx; border-right: 1px solid #eee; color: #666;}
	.flex .flex-i:last-child {border: 0;}
	.flex .flex-i text {display: inline-block; padding-left: 8upx;}
	.banner {position: relative; height: 511upx; border-bottom: 1px solid #eee; background-color: #fff;}
	.banner .panel {position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 85%; padding: 30upx 30upx 40upx; border-radius: 38upx; box-shadow: 1px 0 5px #f4e9fd; background: url(../../static/31.png) no-repeat bottom; background-size: 100%; background-color: #fff;}
	.banner .panel .name {display: block;}
	.banner .panel .logo {position: relative; width: 150upx; margin: 0 auto;}
	.banner .panel .logo image {border-radius: 100%;}
	.banner .panel .logo .vip {position: absolute; bottom: 10upx; right: 0; width: 35upx; z-index: 99;}
	.banner .panel .fans {margin: 20upx 0; text-align: center;}
	.banner .panel .btn {display: inline-block; width: 35%; height: 50upx; border-radius: 50upx; line-height: 50upx; color: #fff; background-color: #82d7d0;}
	.banner .panel .btn.p {background-color: #eee; color: #aaa;}
	.banner .panel .link {position: absolute; width: 32upx;  margin: 10upx 0 0 30upx; vertical-align: middle;}
	.banner .panel .bg {position: absolute; bottom: 0; left: 0;}
	.summary {position: relative; margin: -20upx 0 20upx; padding: 0 30upx 30upx; text-align: left; background-color: #fff; z-index: 11;}
	.summary text {color: #666;}
	.summary .btn {margin: 20upx auto; width: 38%; height: 55upx; text-align: center; border: 1px solid #82d7d0; border-radius: 55upx; line-height: 52upx; color: #06a396; background-color: #f2fbfa;}
	.aptitude {margin-bottom: 20upx; background-color: #fff; text-align: left;}
	.aptitude text {display: block; padding: 20upx 30upx; border-bottom: 1px solid #eee; font-size: 30upx;}
	.aptitude .pic {padding: 20upx 10upx;}
	.aptitude .pic image {width: 25%; padding: 0 10upx;}
	/** 图文分类菜单 */
	.classify {width: 100%; padding: 0 20upx; background-color: #fff;}
	.classify .class-i {float: left; margin: 0 20upx; padding: 20upx 10upx; line-height: 1; font-size: 30rpx; color: #888;}
	.classify .class-i.on {color: #82d7d0; border-bottom: 2px solid #82d7d0;}
</style>
